package com.example.monitoringsystem.controller;


import com.example.monitoringsystem.bean.Doctor;
import com.example.monitoringsystem.bean.User;
import com.example.monitoringsystem.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


import java.util.List;
import java.util.Map;


/**
 * 患者选择医生模块
 */

@Controller
@RequestMapping("/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;


    //选择医生
    //@PostMapping(value = "/choose",produces = "application/json; charset=utf-8")
    @PostMapping("/choose")
    @ResponseBody
    public String chooseDoctor(int doctorId, Model model){
        boolean result = patientService.chooseDoctorByDoctorId(doctorId);
        if (result){
            return "选择医生成功";
        }else{
            return "选择医生失败";
        }
    }

    //查看全部医生
    //返回医生用户信息
    @GetMapping("/search/doctorUsers")
    @ResponseBody
    public List searchDoctorUsers(){
        List<User> list;
        list=patientService.getAllDoctorUsers();
        return list;
    }

    //返回医生信息
    @GetMapping("/search/doctors")
    @ResponseBody
    public List searchDoctors(){
        List<Doctor> list;
        list=patientService.getAllDoctors();
        return list;
    }

    //查看单个医生
    @GetMapping(value = "/search/one",produces = "application/json; charset=utf-8")
    @ResponseBody
    public String searchOneDoctor(int doctorId, Map<String,Object>map){
        Map<String,Object> doctorMap = patientService.getDoctorByDoctorId(doctorId);
        Doctor doctor=(Doctor) doctorMap.get("doctor");
        User user=(User)doctorMap.get("user");
        map.put("doctor",doctor);
        map.put("user",user);
        return "向前端返回doctor和user对象";
    }

}
